#define _CRT_SECURE_NO_WARNINGS 1
#include"sqstack.h"

struct sqstack_st
{
	datatype data[MAXSIZE];
	int top;
};


SQSTACK* st_create(void) {
	struct sqstack_st* st;
	st = malloc(sizeof(*st));
	if (!st)
		return NULL;

	st->top = -1;
	return st;
}
void st_destroy(SQSTACK* s) {
	struct sqstack_st* st=s;
	free(st);
}
void st_travel(SQSTACK* s) {
	int i;
	struct sqstack_st* st = s;
	if (st_isempty(st))
		return;
	for (i = 0; i <= st->top; i++)
		printf("%d ", st->data[i]);
	printf("\n");
}
int st_isempty(SQSTACK* s) 
{
	struct sqstack_st* st = s;
	return (st->top == -1);
}
int st_push(SQSTACK* s, datatype* data) 
{
	struct sqstack_st* st = s;
	if (st->top >= (MAXSIZE-1))
		return -1;
	st->data[++st->top] = *data;
	return 0;
}
int st_pop(SQSTACK* s, datatype* data) 
{
	struct sqstack_st* st = s;
	if (st_isempty(st))
		return -1;
	*data = st->data[st->top];
	st->top--;
	return 0;
}
int st_top(SQSTACK* s, datatype* data) 
{
	struct sqstack_st* st = s;
	if (st_isempty(st))
		return -1;
	*data = st->data[st->top];
	return 0;
}